package com.yhp.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.system.comm.util.JsonUtils;
import com.system.common.pojo.BisNurseProject;
import com.yhp.service.FrontBisNurseProjectService;

@Controller
@RequestMapping("fbnp")
public class FrontBisNurseProjectController {
	@Autowired
	private FrontBisNurseProjectService bisNurseProjectService;
	

	/**
	 * 护理项目>>>>>>列表显示所有
	 * 
	 * @return
	 */
	@RequestMapping("front_project")
	public String front_project(HttpServletRequest request, Model model) {
		Map<String, Object> map = initMap(request);
		List<BisNurseProject> bisNurseProject = bisNurseProjectService.selectByExample(map);
		model.addAttribute("bisNurseProject", bisNurseProject);
		return "bis_nurse/front_project";
	}

	public Map<String, Object> initMap(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<>();
		String projectId = request.getParameter("projectId");
		String projectName = request.getParameter("projectName");
		String rmbPrice1 = request.getParameter("rmbPrice1");
		String rmbPrice2 = request.getParameter("rmbPrice2");
		if (projectId != null && !projectId.equals("")) {
			map.put("projectId", projectId);
		}
		if (projectName != null && !projectName.equals("")) {
			map.put("projectName", projectName);
		}
		if (rmbPrice1 != null && !rmbPrice1.equals("")) {
			map.put("rmbPrice1", rmbPrice1);
		}
		if (rmbPrice2 != null && !rmbPrice2.equals("")) {
			map.put("rmbPrice2", rmbPrice2);
		}
		return map;
	}
	
	/**
	 * 护理项目>>>>>>查看详情
	 * 
	 * @return
	 */
	@RequestMapping(value="front_project_details",produces = "application/json;charset=utf-8")
	@ResponseBody
	public String front_project_details(HttpServletRequest request) {
		String projectId=request.getParameter("projectId");
		BisNurseProject bisNurseProject = bisNurseProjectService.selectByPrimaryKey(projectId);
		return JsonUtils.toJson(bisNurseProject);
	}
}